package carassius.BLL;

import carassius.DAL.AnimalRow;
import java.io.IOException;
import java.net.URL;

/**
 *
 * @author siebz0r
 */
public class FishPage implements Comparable<FishPage>
{
	private final String NAME;
	private final URL LINK;
	private AnimalRow _animalRow;

	public FishPage(String name, URL link)
	{
		NAME= name;
		LINK = link;
	}

	public FishPage(String name, URL link, AnimalRow animalRow)
	{
		NAME= name;
		LINK = link;
		_animalRow = animalRow;
	}

	public URL getLink()
	{
		return LINK;
	}

	public String getName()
	{
		return NAME;
	}

	public AnimalRow getAnimalRow() throws IOException
	{
		if(_animalRow == null)
		{
			_animalRow = AquavisieImporter.getFish(LINK);
		}
		return _animalRow;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (obj == null)
		{
			return false;
		}
		if (getClass() != obj.getClass())
		{
			return false;
		}
		final FishPage other = (FishPage) obj;
		if ((this.NAME == null) ? (other.NAME != null) : !this.NAME.equals(other.NAME))
		{
			return false;
		}
		if (this.LINK != other.LINK && (this.LINK == null || !this.LINK.equals(other.LINK)))
		{
			return false;
		}
		if (this._animalRow != other._animalRow && (this._animalRow == null || !this._animalRow.equals(other._animalRow)))
		{
			return false;
		}
		return true;
	}

	@Override
	public int hashCode()
	{
		int hash = 5;
		return hash;
	}

	@Override
	public String toString()
	{
		return getName();
	}

	@Override
	public int compareTo(FishPage o)
	{
		return toString().compareTo(o.toString());
	}
}
